package b_threadAPI;
/*
    常用API
 */
public class TreadAPIDemo01 {
    public static void main(String[] args) {

        Thread t1 = new Thread("线程1"){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    //获取当先线程
                    Thread t = Thread.currentThread();
                    //获取当先线程名字
                    String name = t.getName();
                    System.out.println("当前线程名字:" + name + ": " +i);
                }
            }
        };
        t1.start();

        System.out.println("--------------------------");

        Thread t2 = new Thread("线程2"){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("休眠前");
                    //让当前线程进入休眠
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("醒了");
                    //获取当先线程
                    Thread t = Thread.currentThread();
                    //获取当先线程名字
                    String name = t.getName();
                    System.out.println("当前线程名字:" + name + ": " +i);
                }
            }
        };
        t2.start();

        /*//设置线程的名字
        t1.setName("线程1");
        t2.setName("线程2");*/


    }
}
